/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gestion_db;

//import java.sql.*;
//import java.util.logging.Level;
//import java.util.logging.Logger;
import modelado.ComUsuarios;
import java.util.ArrayList;
import java.sql.*;
import javax.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author oosorio
 */
public class db_usuarios {

    public ArrayList ObtenerResultSet(String consulta_sql) {
        ArrayList arry = new ArrayList();
        String msj = null;
        ResultSet rs = null;
        Connection cn;
        Statement st;
        // Connection cn = null;
        try {
            Context ctx = new InitialContext();
            DataSource ds = (DataSource) ctx.lookup("jdbc/comprasdb");
            cn = ds.getConnection();
            st = cn.createStatement();
            rs = st.executeQuery(consulta_sql);
            rs.beforeFirst();
            while (rs.next()) {
                ComUsuarios usr = new ComUsuarios(rs.getInt("Usuarioid"), rs.getString("nombre"), rs.getString("nombreCompleto"), rs.getString("correo"), rs.getInt("usuarioAutorizaID"), rs.getString("clave"), rs.getString("estado"), rs.getString("fechaAlta"), rs.getString("fechaBaja"), rs.getInt("perfilID"));
                arry.add(usr);
                msj = "OK";
                
            }
            rs.close();
            st.close();
            cn.close();
        } catch (Exception ex) {
            arry = null;
            msj = ex.toString();
        }
        return arry;
    }
}
